import {reqAddressInfo,reqOrderInfo} from '@/api'
const state = {
    userAddress:[],
    orderInfo:{}
}
const mutations = {
    GETUSERADDRESS(state,userAddress){
        state.userAddress = userAddress||[]
    },
    GETORDERINFO(state,orderInfo){
        state.orderInfo = orderInfo
    },
}
const actions = {
   async getUserAddress({commit}){
    let result = await reqAddressInfo();
    if(result.code === 200){
        commit('GETUSERADDRESS',result.data)
    }
   },
   async getOrderInfo({commit}){
    let result = await reqOrderInfo();
    if(result.code === 200){
        commit('GETORDERINFO',result.data)
    }
   },
}
const getters = {
    addressInfo(state){
        /* let result = state.userAddress.every((item) => item.isDefault == 0);
        if(result){
            state.userAddress[0].isDefault = '1'
        } */
        return state.userAddress
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}